<?php

/**
 * IndexController - The default controller class
 * 
 * @author
 * @version 
 */

require_once 'Zend/Controller/Action.php';

class Adminb_FavorController extends App_Zend_Controller_Action_Adminb 
{
	

	
	public function init(){
		parent::init();
		$member=new CMember();
		
		if(!$member->isUser($this->_request->getModuleName(),$this->_request->getControllerName())){
			
				$this->_redirect(MY_URL.'/auth-login');
			
		}
		
	}
	
	public function preDispatch()
	{

		$this->getHelper ('layout')->setLayout('framelayout');
		
		$this->view->addHelperPath(MY_ROOT.'/vhelpers');
		
		Zend_Controller_Action_HelperBroker::addPath(MY_ROOT.'/chelpers');

	}

	
    public function itemsAction() 
    { 	
    	
    	$page=$this->_request->getParam('page',1);
    	
    	$itemFavor=new CFavor('item');
    	
    	$favorCounts=$itemFavor->getFavorCounts(array('uid'=>$_COOKIE[COOKIE_PRE.'uid']));
    	
    	$favorArray=$itemFavor->getFavors(array('uid'=>$_COOKIE[COOKIE_PRE.'uid']));
	
    	Zend_Loader::loadClass("CFilter");	
    	
    	$pageArray = CFilter::filterPage ( $page, $favorCounts, 10 );
		
		Zend_Loader::loadClass("CPage");
    	
    	$pageString = CPage::divPagesAdmin( $pageArray ['pageNumber'], $pageArray ['page'], ROOT_PATH."/adminb-favor-items?"); //生成分页字符串
    	
    	$this->view->assign ( "pageString", $pageString );
    	
    	$this->view->assign ( "pageArray", $pageArray );
    	
    	$this->view->assign ( "favorArray", $favorArray );

    }
    
    public function sellersAction(){

    	$page=$this->_request->getParam('page',1);
    	
    	$sellerFavor=new CFavor('member');
    	
    	$favorCounts=$sellerFavor->getFavorCounts(array('uid'=>$_COOKIE[COOKIE_PRE.'uid']));
    	
    	$favorArray=$sellerFavor->getFavors(array('uid'=>$_COOKIE[COOKIE_PRE.'uid']));
	
    	Zend_Loader::loadClass("CFilter");	
    	
    	$pageArray = CFilter::filterPage ( $page, $favorCounts, 10 );
		
		Zend_Loader::loadClass("CPage");
    	
    	$pageString = CPage::divPages( $pageArray ['pageNumber'], $pageArray ['page'], ROOT_PATH."/adminb-favor-sellers?"); //生成分页字符串
    	
    	$this->view->assign ( "pageString", $pageString );
    	
    	$this->view->assign ( "pageArray", $pageArray );
    	
    	$this->view->assign ( "favorArray", $favorArray );

    }
    
    public function categoriesAction(){

    	$page=$this->_request->getParam('page',1);
    	
    	$cateFavor=new CFavor('cate');
    	
    	$favorCounts=$cateFavor->getFavorCounts(array('uid'=>$_COOKIE[COOKIE_PRE.'uid']));
    	
    	$favorArray=$cateFavor->getFavors(array('uid'=>$_COOKIE[COOKIE_PRE.'uid']));
	
    	Zend_Loader::loadClass("CFilter");	
    	
    	$pageArray = CFilter::filterPage ( $page, $favorCounts, 10 );
		
		Zend_Loader::loadClass("CPage");
    	
    	$pageString = CPage::divPages( $pageArray ['pageNumber'], $pageArray ['page'], ROOT_PATH."/adminb-favor-categories?"); //生成分页字符串
    	
    	$this->view->assign ( "pageString", $pageString );
    	
    	$this->view->assign ( "pageArray", $pageArray );
    	
    	$this->view->assign ( "favorArray", $favorArray );

    }
    
    public function doadditemAction(){
    	
    	$this->_helper->viewRenderer->setNoRender();
    	
    	$this->getHelper ('layout')->disableLayout ();
    	
    	$itemid=$this->_request->getParam('itemid');
    	
    	$itemFavor=new CFavor('item');
    	
    	$data=array(
    				'uid'=>$_COOKIE[COOKIE_PRE.'uid'],
    				'itemid'=>$itemid,
    				'add_time'=>time()
    				);
    	
    	if($itemFavor->createFavor($data)){
    		
    		echo 'success';
    		
    	}else{
    		
    		echo 'error';
    		
    	}
    	
    }
    
    public function doaddcateAction(){
    	
        $this->_helper->viewRenderer->setNoRender();
    	
    	$this->getHelper ('layout')->disableLayout ();
    	
    	$flid=$this->_request->getParam('flid');
    	
    	$flFavor=new CFavor('cate');
    	
    	$data=array(
    				'uid'=>$_COOKIE[COOKIE_PRE.'uid'],
    				'flid'=>$flid,
    				'add_time'=>time()
    				);
    	
    	if($flFavor->createFavor($data)){
    		
    		echo 'success';
    		
    	}else{
    		
    		echo 'error';
    		
    	}
    	
    }
	
    public function doaddmemberAction(){
    	
        $this->_helper->viewRenderer->setNoRender();
    	
    	$this->getHelper ('layout')->disableLayout ();
    	
    	$favor_uid=$this->_request->getParam('favor_uid');
    	
    	$memberFavor=new CFavor('member');
    	
    	$data=array(
    				'uid'=>$_COOKIE[COOKIE_PRE.'uid'],
    				'favor_uid'=>$favor_uid,
    				'add_time'=>time()
    				);
    	
    	if($memberFavor->createFavor($data)){
    		
    		echo 'success';
    		
    	}else{
    		
    		echo 'error';
    		
    	}
    	
    }
    
    public function dodelitemAction(){    	
    	
    	$this->_helper->viewRenderer->setNoRender();
		    	
    	$id=$this->_request->getParam('id');
    	
    	if($id==''){
    		
    		$idArray=$this->_request->getParam('itemArray');
    		
    	}else{
    		
    		$idArray=array($id);
    		
    	}
    	
    	$favor=new CFavor('item');
    	
    	$favor->delFavor('itemid',$idArray);    	
    	
    	$this->view->showMsg("Deleted!");
    	
    }
    
    
    public function dodelsellerAction(){
    	
    	$this->_helper->viewRenderer->setNoRender();
    	
    	$id=$this->_request->getParam('id');
    	
    	if($id==''){
    		
    		$idArray=$this->_request->getParam('itemArray');
    		
    	}else{
    		
    		$idArray=array($id);
    		
    	}
    	
    	$favor=new CFavor('member');
    	
    	$favor->delFavor('favor_uid',$idArray);
    	
    	$this->view->showMsg("Deleted!");
    	
    }
    
    public function dodelcateAction(){
    	
    	$this->_helper->viewRenderer->setNoRender();
    	
    	$id=$this->_request->getParam('id');
    	
    	if($id==''){
    		
    		$idArray=$this->_request->getParam('itemArray');
    		
    	}else{
    		
    		$idArray=array($id);
    		
    	}
    	
    	$favor=new CFavor('cate');
    	
    	$favor->delFavor('flid',$idArray);
    	
    	$this->view->showMsg("Delete success!");
    	
    }
    
	public function postAction(){
	
		//$this->_helper->viewRenderer->setNoRender();
		
		//$this->getHelper ('layout')->disableLayout ();
	
	}
    

    
}
